package com.example.service;
import org.springframework.stereotype.Service;
import com.example.entity.Order;
import com.example.entity.OrderType;
@Service
public class FareCalculator {
    public double calculate(Order order) {
        double baseFare = 0;
        double distanceFare = 0;
        double timeFare = 0;
        double tolls = 0;

        switch (order.getType()) {
            case ECONOMY:
                baseFare = 8 + (order.getDistance() > 3 ? (order.getDistance() - 3) * 1.5 : 0);
                distanceFare = order.getDistance() * 1.8;
                timeFare = order.getDuration() * 0.3;
                break;
            case LUXURY:
                baseFare = 15 + (order.getDistance() > 5 ? (order.getDistance() - 5) * 2.5 : 0);
                distanceFare = order.getDistance() * 3.5;
                timeFare = order.getDuration() * 0.5;
                break;
            case AUTONOMOUS:
                baseFare = 8 * 1.3;
                distanceFare = order.getDistance() * 1.8 * 1.3;
                timeFare = order.getDuration() * 0.3 * 1.3;
                break;
            case CARPOOL:
                // 拼车费用分摊逻辑
                break;
        }

        if (order.getDistance() > 20) {
            distanceFare *= 1.2;
        }

        return baseFare + distanceFare + timeFare + tolls;
    }
}    